package com.bop.dehong.setting;

import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.base.dehong.base.AdapterBase;
import com.bop.dehong.R;
import com.bop.dehong.info.entity.BankCardItemEntity;

/**
 * @author Tangwenhan
 *2015年11月24日上午11:04:42
 */
public class BankCardAdapter extends AdapterBase<BankCardItemEntity>{
	 private int mRightWidth = 0;

	public BankCardAdapter(Activity context, int rightWidth) {
		super(context);
		mRightWidth = rightWidth;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_bankcard_info_list, null);
			holder.avatarIv = getView(convertView, R.id.imageView1);
			holder.bank = getView(convertView, R.id.textView1);
			holder.card = getView(convertView, R.id.textView2);
			holder.delete = getView(convertView, R.id.delete);
			holder.moren = getView(convertView, R.id.moren);
			holder.leftLayout = getView(convertView, R.id.left_layout);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		 LinearLayout.LayoutParams lp1 = new LayoutParams(LayoutParams.MATCH_PARENT,
	                LayoutParams.MATCH_PARENT);
	     holder.leftLayout.setLayoutParams(lp1);
	     
	     LinearLayout.LayoutParams lp2 = new LayoutParams(mRightWidth, LayoutParams.MATCH_PARENT);
	     holder.delete.setLayoutParams(lp2);
	     holder.moren.setVisibility(View.INVISIBLE);
	     BankCardItemEntity info = get(position);
	     if (info != null) {
			holder.bank.setText(info.getBank_name());
			holder.card.setText("尾号 "+info.getBank_account());
			String isdefault = info.getIsdefaultme();
			if (TextUtils.equals(isdefault, "1")) {
				holder.moren.setVisibility(View.VISIBLE);
			}
			holder.delete.setOnClickListener(new OnClickListener() {
	            @Override
	            public void onClick(View v) {
	                if (mListener != null) {
	                    mListener.onRightItemClick(v, position);
	                }
	            }
	        });
		}
		
		return convertView;
	}

	private class ViewHolder {
		//时间
		private ImageView avatarIv;

		//银行
		private TextView bank;
		//卡号
		private TextView card;
		private TextView moren;
		//删除
		private Button delete;
		private LinearLayout leftLayout;

	}
	/**
     * 单击事件监听器
     */
    private onRightItemClickListener mListener = null;
    
    public void setOnRightItemClickListener(onRightItemClickListener listener){
    	mListener = listener;
    }
    public interface onRightItemClickListener {
        void onRightItemClick(View v, int position);
    }

}

